package com.ruoyi.crm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.MongoLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.Clue;
import com.ruoyi.crm.domain.vo.CluesTrackVo;
import com.ruoyi.crm.domain.vo.FalseClueVo;
import com.ruoyi.crm.domain.vo.TransformVo;
import com.ruoyi.crm.service.IClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/crm/clueTrack")
public class CluesTrackController extends BaseController{
    @Autowired
    private IClueService clueService;

    @PreAuthorize("@ss.hasAnyPermi('crm:business:edit')")
//    @Log(title = "线索跟踪记录",businessType = BusinessType.INSERT)
    @MongoLog(tableName = MongoLog.TableName.CLUE,title = "线索跟踪记录",businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CluesTrackVo cluesTrackVo){
        cluesTrackVo.setStatus(Clue.Status.TRACKING.getValue());
        return toAjax(clueService.updateClue(cluesTrackVo));
    }

    @PreAuthorize("@ss.hasAnyPermi('crm:business:edit')")
//    @Log(title = "线索跟踪记录",businessType = BusinessType.INSERT)
    @MongoLog(tableName = MongoLog.TableName.CLUE,title = "线索跟踪记录",businessType = BusinessType.INSERT)
    @PutMapping("/falseClue")
    public AjaxResult falseClue(@RequestBody FalseClueVo falseClueVo){
        return toAjax(clueService.falseClue(falseClueVo.getId()));
    }

    @Log(title = "线索跟踪记录")
    @PutMapping("/resetClue")
    public AjaxResult resetClue(@RequestBody TransformVo transformVo){
        return toAjax(clueService.resetClue(transformVo.getId()));
    }

    @Log(title = "线索跟踪记录")
    @PutMapping("/transform")
    public AjaxResult transform(@RequestBody TransformVo transformVo){
        return toAjax(clueService.transformBusiness(transformVo.getId()));
    }

}
